package engine.control
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	import newx.com.control.NxClip;
	import newx.com.control.text.NxText;
	
	public class ImageItem extends Sprite
	{
		private var _image:NxClip;
		
		private var loadCheck		:Boolean	=	false
			
		private var _id			:int		=	0;
				
		private var _imgWidth		:uint		=	20;
		
		private var _imgHeight		:uint		=	20;
		
		private var _txtSpace		:NxText;
		
		private var _textVisible	:Boolean	=	false;
		
		private var _labelWidth	:int;
		
		public function ImageItem(defaultImageClass:String)
		{
			_image				=	new NxClip();
			
			_image.isCache		=	true;
			
			loadCheck			=	false;
			_image.addLoadedEvent(onLoadImg,Event.COMPLETE);
			creatImageSpace();
			
			_txtSpace	=	new NxText();				
			_txtSpace.width	=	95;
			_txtSpace.height=	50;
			_txtSpace.vScrollSkin	=	"vScrol_1";
			_txtSpace.hScrollSkin	=	"vScrol_2";
			_txtSpace.mouseChildren	=	false;
			_txtSpace.mouseEnabled	=	false;
			_txtSpace.color			=	0xFFFFFF;
			
		}
		
		public function get labelWidth():int
		{
			return _labelWidth;
		}

		public function set labelWidth(value:int):void
		{
			_labelWidth 	= value;
			scrollRect	=	new Rectangle(0,0,_txtSpace.x+value,this.height);
		}

		public function get imgHeight():uint
		{
			return _imgHeight;
		}

		public function set imgHeight(value:uint):void
		{
			_imgHeight = value;
			if(loadCheck)
			{
				_image.height	=	_imgHeight;
			}
		}

		public function get imgWidth():uint
		{
			return _imgWidth;
		}

		public function set imgWidth(value:uint):void
		{
			_imgWidth = value;
			if(loadCheck)
			{				
				_image.width	=	_imgWidth;
			}			
		}

		private function creatImageSpace():void
		{
			addChild(_image);
		}
		
		public function set image(val:Object):void
		{
			if(val == "")
			{
				_image.clear();
			}
			else
			{
				_image.source	= val;
			}
		}
		
		public function get image():Object
		{
			return _image.content;
		}
		
		private function onLoadImg(val:DisplayObject):void
		{
			if(!loadCheck)
			{
				_image.width		=	_imgWidth;
				_image.height		=	_imgHeight;
				loadCheck		=	true;
			}
		}
		
		public function remove():void
		{
			this.parent.removeChild(this);
		}
		
		public function set textVisible(val:Boolean):void
		{
			_textVisible	=	val;
			if(_textVisible == true)
			{
				if(_txtSpace.parent == null)
				{
					addChild(_txtSpace);
				}
			}
			else
			{
				if(_txtSpace.parent != null)
				{
					removeChild(_txtSpace);
				}
			}
		}
		
		public function get textVisible():Boolean
		{
			return _textVisible;
		}

		public function get txtSpace():NxText
		{
			return _txtSpace;
		}

		public function set txtSpace(value:NxText):void
		{
			_txtSpace = value;
		}
		
		public function clear():void
		{
			_txtSpace.htmlStr	=	"";
			textVisible			=	false;
			_image.clear();
		}

	}
}